package com.wt.admin.controller.sys;

import com.aizuda.easy.security.domain.Rep;
import com.aizuda.easy.security.domain.Req;
import com.wt.admin.config.aspect.annotation.LogAno;
import com.wt.admin.domain.dto.sys.SysUserInfoUpdateDTO;
import com.wt.admin.domain.dto.sys.SysUserLoginDTO;
import com.wt.admin.domain.dto.sys.SysUserPasswordDTO;
import com.wt.admin.domain.entity.sys.SysUserEntity;
import com.wt.admin.domain.vo.sys.SysUserListVO;
import com.wt.admin.domain.vo.sys.UserVO;
import com.wt.admin.service.sys.SysUserService;
import com.wt.admin.util.PageUtil;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import jakarta.annotation.Resource;


@RestController
@RequestMapping("user")
public class SysUserController {

    @Resource
    private SysUserService sysUserService;

    @LogAno(name = "登录")
    @PostMapping("login")
    public Rep<UserVO> login(@RequestBody Req<SysUserLoginDTO,UserVO> req){
        return Rep.ok(sysUserService.login(req.getData()));
    }

    @LogAno(name = "用户列表")
    @PostMapping("find")
    public Rep<SysUserListVO> find(@RequestBody Req<PageUtil.PageDTO<SysUserEntity>,UserVO> req){
        return Rep.ok(sysUserService.find(req.getData()));
    }

    @LogAno(name = "修改或添加用户")
    @PostMapping("edit")
    public Rep<SysUserEntity> edit(@RequestBody Req<SysUserEntity,UserVO> req){
        return Rep.ok(sysUserService.edit(req.getData()));
    }

    @LogAno(name = "删除用户")
    @PostMapping("del")
    public Rep<SysUserEntity> del(@RequestBody Req<SysUserEntity,UserVO> req){
        return Rep.ok(sysUserService.del(req.getData()));
    }

    @LogAno(name = "修改用户密码")
    @PostMapping("updatePassword")
    public Rep<SysUserEntity> updatePassword(@RequestBody Req<SysUserPasswordDTO,UserVO> req){
        return Rep.ok(sysUserService.updatePassword(req.getData()));
    }

    @LogAno(name = "用户信息查询")
    @PostMapping("info")
    public Rep<SysUserEntity> info(@RequestBody Req<SysUserPasswordDTO,UserVO> req){
        return Rep.ok(sysUserService.info(req.getUser()));
    }

    @LogAno(name = "用户修改自己信息")
    @PostMapping("updateInfo")
    public Rep<SysUserEntity> updateInfo(@RequestBody Req<SysUserInfoUpdateDTO,UserVO> req){
        return Rep.ok(sysUserService.updateInfo(req.getData()));
    }


}
